unit uFrmMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Oracle, StdCtrls, Grids, ExtCtrls, inifiles;

type
  TFrmMain = class(TForm)
    Timer1: TTimer;
    stg_Tournaments: TStringGrid;
    Label1: TLabel;
    OracleQuery1: TOracleQuery;
    OracleSession1: TOracleSession;
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
    GridScroolPos: integer;
    procedure GetIniFile();
    procedure GetData();
    procedure SetFixedRowsText();
  public
    { Public declarations }
  end;

var
  FrmMain: TFrmMain;

implementation

{$R *.dfm}

procedure TFrmMain.FormCreate(Sender: TObject);
begin
  GridScroolPos := 0;
  GetIniFile();
  SetFixedRowsText();
end;

procedure TFrmMain.GetData;
var
  C, R: integer;
begin
  // ERASE GRID
  for R := 1 to stg_Tournaments.RowCount - 1 do
  begin
    for C := 0 to stg_Tournaments.ColCount - 1 do
    begin
      stg_Tournaments.Cells[C, R] := '';
    end;
  end;
  // SET DATA
  OracleQuery1.Close;
  OracleQuery1.SQL.Text := 'select TIME, DAY, NAME, BUY_IN, PLAYERS, MONEY_PRIZE from GETTICKETTOURNAMENTS where event_start>(select sysdate from dual)-1';
  OracleQuery1.Execute;
  R := 1;
  while not OracleQuery1.Eof do
  begin
    for C := 0 to stg_Tournaments.ColCount - 1 do
    begin
      stg_Tournaments.Cells[C, R] := OracleQuery1.Field(C);
    end;
    inc(R);
    OracleQuery1.Next;
  end;
end;

procedure TFrmMain.GetIniFile();
var
  appINI: Tinifile;
  iniFileName, Language: string;
begin
  iniFileName := ExtractFilePath(Application.ExeName) + '\' + 'LPM.ini';
  if not FileExists(iniFileName) then
  begin
    FileCreate(iniFileName);
  end
  else
  begin
    appINI := Tinifile.Create(iniFileName);
    try
      OracleSession1.LogonUsername := appINI.ReadString('Database', 'User', '');
      OracleSession1.LogonPassword := appINI.ReadString('Database', 'Pass', '');
      OracleSession1.LogonDatabase := appINI.ReadString('Database', 'TNS', '');
      OracleSession1.LogOn;
      OracleQuery1.Session := OracleSession1;
    finally
      appINI.free;
    end;
  end;
end;

procedure TFrmMain.SetFixedRowsText;
begin
  stg_Tournaments.Cells[0, 0] := 'TIME';
  stg_Tournaments.Cells[1, 0] := 'DAY';
  stg_Tournaments.Cells[2, 0] := 'NAME';
  stg_Tournaments.Cells[3, 0] := 'BUY_IN';
  stg_Tournaments.Cells[4, 0] := 'PLAYERS';
  stg_Tournaments.Cells[5, 0] := 'MONEY PRIZE';
end;

procedure TFrmMain.Timer1Timer(Sender: TObject);
begin
  if OracleSession1.Connected then
  begin
    GetData();
  end;
end;

end.
